<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*" import="com.dr.pojo.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>UserList</title>

<!-- ================================= CSS ===========================================  -->
<style type="text/css">
	*{
		font-size: 16px;
		margin: 0;
		padding: 0;
	}
	div{
		width: 1000px;
		margin: 0 auto;
		margin-top: 10px;
	}
	table{
		width: 100%;
		
	}
	.table_list{
		border: solid 1px;
		border-collapse: collapse;
	}
	.table_list th, td{
		border: solid 1px gray;
		padding: 5px;
		text-align: center;
	}
	h4{
		margin-bottom: 5px;
	}
	p{
		padding: 5px;
		margin-bottom: 5px;
	}
	input{
		padding: 3px;
	}
</style>

<!-- ================================= JavaScript ===========================================  -->

<script type="text/javascript" src="/lib/jquery-3.4.1.js"></script>
<script type="text/javascript">
	$(function(){
		$('#btnAdd').click(function(){
			$('#frm').attr("action","/um/toAdd");
			$('#frm').submit();
		});
	});

	function delUser(id,name){
		var msg = "确认删除用户：" + name + "？";
		msg += "\n单击确认将执行删除，单击取消则撤销删除。";
		if(confirm(msg) == true){
			var frm = document.getElementById('frm');
			frm.action = "/um/doDelete?id=" + id;
			frm.submit();
		}
	}
</script>
</head>

<!-- ================================= Body ===========================================  -->
<body>
	<div>
		<h4>系统用户查询</h4>
		<form id="frm" action="/um/userListByName" method="post">
		<p>
			<input type="search" name="txtQuery" 
				   value="<%=request.getAttribute("txtQuery") == null?"":request.getAttribute("txtQuery") %>" 
				   placeholder="请输入用户名">
			<input type="submit" value="查询用户">
			<input type="button" value="增加用户 " id="btnAdd">
		</p>
		</form>			
		<hr>			
		<h4>系统用户列表</h4>
			<table class="table_list">
				<tr>
					<th>系统账户</th>
					<th>用户名</th>
					<th>岗位</th>
					<th>部门</th>
					<th>操作</th>			
				</tr>
<%
	List<User> userlist = (List)request.getAttribute("userList");
	if(userlist.size() == 0 || userlist == null){
		return;
	}
	
	for(User user : userlist){
		//out.println(user);
		%>
		<tr>
			<td><%=user.getAccount() %></td>
			<td><%=user.getName() %></td>
			<td><%=user.getJob() %></td>			
			<td><%=user.getDeptName() %></td>						
			<td>
				<a href="/um/toUpdate?id=<%=user.getId() %>">修改</a> &nbsp;&nbsp;&nbsp;
				<!-- <a href="/um/doDelete?id=<%=user.getId() %>">删除</a> 	 -->			
				<a href="javascript:delUser(<%=user.getId() %>,'<%=user.getName() %>')">删除</a> 				
			</td>		
		</tr>
		<%
	}
%>
		</table>
		
	</div>
</body>
</html>